//
//  CHDBTableViewCell.m
//  CarFile
//
//  Created by 陈浩 on 2017/7/31.
//  Copyright © 2017年 陈浩. All rights reserved.
//

#import "CHDBTableViewCell.h"
#import "CHPhotosView.h"
#import "CHEvaluationListModel.h"
@interface CHDBTableViewCell ()
{
    UILabel *titleLabel;
    UILabel *timeLabel;
    UILabel *phoneLabel;
    UIImageView *iconImgView;      //   头像
    UIButton *dbBtn;
    UIButton *repairBtn;
    UILabel *evaluatedetailsLabel;      //  用户反馈
    UILabel *valuatevalueLabel;       //  企业回复
    UIImageView *picImgView;
    CHPhotosView *photosView;

}
@property (nonatomic ,strong) NSMutableArray *views;
@end
@implementation CHDBTableViewCell
-(NSMutableArray *)views{
    
    
    if (!_views) {
        _views = [NSMutableArray array];
    }
    return _views;
}
- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

+(instancetype)cellForTableView:(UITableView *)tableView{
    static NSString *ID = @"CHDBTableViewCell";
    CHDBTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:ID];
    if (!cell) {
        cell = [[CHDBTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:ID];
    }
    return cell;
    
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self buildUI];
        
    }
    return self;
    
}


-(void)buildUI{
    
    

    titleLabel = [[UILabel alloc] init];
    titleLabel.numberOfLines  = 0;
    titleLabel.textColor =  [UIColor colorWithHexString:@"168bce" alpha:1.0f];
    titleLabel.font = [UIFont systemFontOfSize:14];
    [self addSubview:titleLabel];
   
    timeLabel = [[UILabel alloc] init];
    timeLabel.textAlignment = NSTextAlignmentRight;
    timeLabel.textColor = [UIColor colorWithHexString:@"666666" alpha:1.0f];
    timeLabel.font = [UIFont systemFontOfSize:12];
    [self addSubview:timeLabel];
   
    
    iconImgView = [[UIImageView alloc] init];
    iconImgView.image = [UIImage imageNamed:@"car_icon"];
    [self addSubview:iconImgView];
    
    
    phoneLabel = [[UILabel alloc] init];
    phoneLabel.font = [UIFont systemFontOfSize:13];
    phoneLabel.textColor = [UIColor colorWithHexString:@"666666" alpha:1.0f];
    [self addSubview:phoneLabel];

    
    dbBtn = [[UIButton alloc] init];
    dbBtn.tag = 100;
    dbBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    dbBtn.userInteractionEnabled = YES;
    dbBtn.layer.cornerRadius = 3;
    dbBtn.layer.masksToBounds = YES;
    [dbBtn setTitle:@"督办" forState:UIControlStateNormal];
    [dbBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [dbBtn setBackgroundColor:[UIColor colorWithHexString:@"168bce" alpha:1.0f]];
    [dbBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:dbBtn];
    
    repairBtn = [[UIButton alloc] init];
    repairBtn.tag = 101;
    repairBtn.userInteractionEnabled = YES;
    repairBtn.titleLabel.font = [UIFont systemFontOfSize:13];
    repairBtn.layer.cornerRadius = 3;
    repairBtn.layer.masksToBounds = YES;
    repairBtn.userInteractionEnabled = YES;
    [repairBtn setTitle:@"维修记录" forState:UIControlStateNormal];
    [repairBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [repairBtn setBackgroundColor:[UIColor colorWithHexString:@"168bce" alpha:1.0f]];
    [repairBtn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
    [self addSubview:repairBtn];
    
    evaluatedetailsLabel = [[UILabel alloc] init];
    evaluatedetailsLabel.numberOfLines = 0;
    evaluatedetailsLabel.font = [UIFont systemFontOfSize:14];
    [self addSubview:evaluatedetailsLabel];
    
    photosView = [[CHPhotosView alloc] init];
    [self addSubview:photosView];
    


}


-(void)setComplainListFrm:(CHComplainListFrame *)complainListFrm{
    _complainListFrm = complainListFrm;
    
    
    // 1. 给子控件设置数据
    [self settingData];
    
    // 2. 根据子控件里面的数据，计算并且设置子控件frame
    [self settingFrame];
    
}


-(void)btnClick:(UIButton *)btn{
    
    if ([self.delegate respondsToSelector:@selector(didBtnClickWithTag:cellIndex:)]) {
        [self.delegate didBtnClickWithTag:btn.tag cellIndex:self.tag];
    }
    
}


-(void)settingData{
    
    CHComplainListModel *model = self.complainListFrm.model;
    titleLabel.text = model.company;
    phoneLabel.text = [model.mobilephone stringByReplacingCharactersInRange:NSMakeRange(3, 4) withString:@"****"];;
    timeLabel.text = model.complainttime;
    evaluatedetailsLabel.text = model.evaluatedetails;
    photosView.pic_urls = [model.complainaccordimg componentsSeparatedByString:@","];
    
}


-(void)settingFrame{

    titleLabel.frame = self.complainListFrm.titleFrm;
    timeLabel.frame = self.complainListFrm.timeFrm;
    iconImgView.frame = self.complainListFrm.iconFrm;
    phoneLabel.frame = self.complainListFrm.phoneFrm;
    dbBtn.frame =  self.complainListFrm.dbFrm;
    repairBtn.frame = self.complainListFrm.wxFrm;
    evaluatedetailsLabel.frame = self.complainListFrm.evaluatedetailsFrm;
    photosView.frame = self.complainListFrm.photosViewFrm;
}


@end
